home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 012 / keystat.arc / KEYSTAT.DOC < prev   
Encoding:
Text File  |  1986-04-14  |  10.6 KB  |  198 lines

  1.  
  2.  
  3.  
  4.        This routine is a resident keyboard interrupt interceptor which displays
  5.        the status of the Capslock and Numlock keys.  If Capslock is on, a "C"
  6.        will be displayed in the upper right hand corner of the display.
  7.        Similarly, a "N" signifies the Numlock mode.
  8.  
  9.             The display is updated after each keystroke.  That is, if you
  10.        install KEYSTAT with capslock on, nothing will be displayed until
  11.        AFTER you strike a key (for more details, see below).
  12.  
  13.        To use the program, type
  14.             KEYSTAT ON
  15.        to install the program or
  16.             KEYSTAT OFF
  17.        to cancel it.  To display the current state, type
  18.             KEYSTAT
  19.        The command syntax is patterned after the DOS BREAK command.
  20.  
  21.        This program requires DOS 2.0 or later.  If loaded on a pre-DOS 2.0 system,
  22.        an error message is displayed.
  23.  
  24.        This routine is called each time a key is pressed.  It will remain resident
  25.        until the system is rebooted or cancelled via the OFF command.  Note, however,
  26.        that the memory allocated to the program when it is installed is NOT freed
  27.        when the routine is turned OFF.  The resident portion of the program takes
  28.        about 650 or so bytes of memory although the operable portion of the program
  29.        (that is, the code that is executed each time a key is pressed) is around
  30.        150 bytes; the available memory reported by CHKDSK, etc... is decreased when
  31.        KEYSTAT is loaded.  Turning KEYSTAT ON, then OFF, then ON again will load another
  32.        copy of the program into memory, decreasing the available memory even further.
  33.        This should not be a problem unless you do this twenty or thirty times.
  34.  
  35.        KEYSTAT simply inserts itself "in series" behind the existing interrupt handler
  36.        and thus SHOULD be compatible with other keyboard utilities such as PROKEY,
  37.        etc... as long as they follow the IBM coding guidelines.  Other programs
  38.        may or may not be compatible with KEYSTAT.  I do not have any of these other
  39.        programs, so there is no way for me to test KEYSTAT with them.  Let me know
  40.        if you have problems using other programs with KEYSTAT.
  41.  
  42.        This program is adapted from an aritcle in October '83 PC-World Magazine,
  43.        page 267.  The author of the original version, called KEYFLAGS, is Morton
  44.        Kaplon.  I found KEYFLAGS to be extremely userful and, as an excercise,
  45.        decided to write my own version.  In the process, I ended
  46.        up adding a few enhancements and changed the name to KEYSTAT.
  47.  
  48.        Here is a summary of the differences between KEYFLAGS and KEYSTAT:
  49.           1. All absolute references to BIOS in KEYFLAGS are replaced by
  50.              interrupts in KEYSTATS.
  51.           2. When KEYSTATS is loaded, it checks to see if it was already
  52.              resident.  KEYFLAGS resets the vector every time, thus allowing
  53.              nesting the code several levels deep.  This was unnecessary since
  54.              the display need only be update once for every keystroke.  Additionally,
  55.              it was undesireable since it would often hang the system.
  56.           3. KEYFLAGS assumed that BIOS was servicing INT 9 and thus
  57.              precluded using PROKEY, etc... with it.  KEYSTAT makes no such
  58.              assumptions.  The previous keyboard service routine, be it BIOS, PROKEY,
  59.              or whatever, is saved and that routine is re-installed when
  60.              KEYSTAT is turned OFF.
  61.           4. Because KEYSTAT uses the new DOS INT 35h, it requires DOS 2.0.
  62.              There is no real reason why this could not be changed to get the
  63.              current interrupt vector directly from memory so that any DOS version
  64.              could be used, but it makes the code a little cleaner.  KEYFLAG can
  65.              be used with any existing version of DOS but compatibility with
  66.              future release is questionable.  KEYSTAT should be compatible with
  67.              future releases of DOS.
  68.           5. KEYFLAGS uses the "@" symbol to signify caps state and the "#" for
  69.              numlock state.  I found these rather cryptic and changed them to
  70.              "C" and "N", respectively in KEYSTAT.
  71.           6. As mentioned earlier, I added command line parameters in KEYSTAT to
  72.              allow for turning the routine OFF and to make it easy to use.
  73.           7. A bug in KEYFLAGS has been fixed in KEYSTAT.  The bug occurs when
  74.              the program is resetting the vector for INT 9.  Should an interrupt
  75.              occur while the vector is being reset, the system will go off into
  76.              computer "never-never land" the next time you press a key.  KEYSTAT
  77.              disables interrupts while this critical section of code is executed.
  78.              Admittedly, this is a rare bug in actual occurence, but it is still
  79.              a bug.
  80.  
  81.        You may make and distribute as many copies of this program as you wish.
  82.        Feel free to modify, mutilate, or adulterate this program.  If you come
  83.        up with an bug or improvement, please let me know by writing me at this
  84.        address:
  85.                Tony A. Rhea
  86.                1030 Ivy Lane
  87.                Cary, NC  27511
  88.        If you do modify it, please give both myself and the original author
  89.        (Morton Kaplon) credit in the program.  This helps to preserve our egos
  90.        and increase our fame (but, unfortunately, NOT our fortunes).  Also, I
  91.        would appreciate a copy of the modified version, preferably on disk (I'll
  92.        be happy to return your diskette).
  93.  
  94.        If you like this program ( or HATE it ), please let me know.  Drop me
  95.        a line at the address given above.
  96.  
  97.        This program has been submitted for publication in PC-WORLD magazine.
  98.  
  99.        I have experimented with an extension of this routine which also displays
  100.        the INSERT and SCROLL-LOCK states as well but found that it caused too much
  101.        overhead -- one could easily "outtype" the system.  Using DOS function 2
  102.        to automatically advance the cursor could eliminate the necessity of moving
  103.        the cursor thru INT 10h since the cursor is automatically advanced when
  104.        the character is displayed.  However, the current display attribute is
  105.        used so the status characters don't stand out very well.  Using DOS function
  106.        9 and printing all the status characters at once from a (constructed) string
  107.        would also work and would allow specifying an "attribute" to use (see the
  108.        discussion of "Extended Screen and Keyboard Control" in chapter 13 of the
  109.        DOS 2.0 manual).  However, that attribute will still be in effect after
  110.        the status characters are displayed.
  111.  
  112.        The initialization code is overlaid by the next program DOS loads so that
  113.        only the ego statement, some variables, and the operable code remain resident.
  114.  
  115.        The video positions are fixed (but can be changed in the equates below)
  116.        and thus will wipe out anything another program puts there.  It is best
  117.        not to put these at the bottom of the screen because the characters would
  118.        be scrolled up.  Putting them at the top of the screen solves this problem.
  119.  
  120.        KEYSTAT waits until BIOS (or whoever) has serviced the keyboard interrupt
  121.        before it updates the display.  This is because it uses the KB_FLAG that
  122.        BIOS (or it's predecessor) must update.  If the user presses the Capslock key,
  123.        KEYSTAT lets the flag be updated first and then gets the flag to sense the
  124.        keyboard status.  If KEYSTAT had updated the display before letting the
  125.        original interrupt servicer update the flag, the display would not be correct
  126.        until the NEXT key is pressed.
  127.  
  128.        Note that INT 25h CANNOT be used for setting a vector permanently.  When your
  129.        program terminates, DOS resets any vectors your program changes.  The only
  130.        way to make the change permanent is by a direct move into the vector table.
  131.  
  132.        I have made heavy use of macros in KEYSTAT -- I find that it enhances the
  133.        readability greatly.  The code is not anything fancy nor is it particuarly
  134.        good, but it works.  This was my first big assembler program (by big I mean
  135.        anything over 10 lines long).  KEYSTAT is a pieced together from code fragments
  136.        from KEYFLAGS and other book and magazine articles.  Therefore, if you find
  137.        that I pushed CS/restored DS when I didn't really need to, it is certainly
  138.        because of my lack of understanding the deeper truths of assembler.  Please
  139.        feel free to improve upon KEYSTAT in any way you see fit.
  140.  
  141.        Pseudocode:
  142.  
  143.          if not(DOS 2.0) then
  144.             error message
  145.             exit
  146.          else
  147.             { we have 2.0 - decode parm }
  148.             get command line parameter
  149.             convert to uppercase
  150.             if (null parameter) then
  151.                { display current status }
  152.                if (already installed) then
  153.                   on message
  154.                else
  155.                   off message
  156.                endif already installed
  157.             else
  158.                { we got a parameter - see if it matches ON }
  159.                if (ON) then
  160.                   if (already resident) then
  161.                      on message
  162.                      exit
  163.                   else
  164.                      make resident
  165.                      on message
  166.                      terminate, leaving operable code resident
  167.                   endif already resident
  168.               else
  169.                   { command wasn't ON -- is it OFF? }
  170.                   if (OFF) then
  171.                      if not(already installed) then
  172.                          off message
  173.                          exit
  174.                      else
  175.                         reset keyboard vector to original servicer
  176.                         off message
  177.                         exit
  178.                      endif not already installed
  179.                   else
  180.                      { we got a command that wasn't OFF or ON }
  181.                      error message
  182.                      exit
  183.                   endif off
  184.                endif on
  185.             endif null parameter
  186.          endif not dos 2.0
  187.  
  188.  
  189.          Revision history:
  190.             rev 1.0  10/15/83                         { original release }
  191.             rev 1.1  10/29/83                         { speed improvement }
  192.  
  193.  
  194.        Copyright (C) 1983  Tony Alan Rhea
  195.        This program may be copied and distributed for personal use
  196.        but not for profit provided this notice is included.  Author makes
  197.        no warranty, expressed or implied, as to the correct nature and
  198.        operation of this software.
  199. d.  Author makes
  200.        no warranty, ex